import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/anime-front-site/#/lazy-loading

Vue.use(Router)

import Layout from '@/views/layout/Layout'

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/
export const constantRouterMap = [

  {
    path: '/login',
    component: () => import('@/views/common/login'),
    hidden: true
  },

  {
    path: '/register',
    component: () => import('@/views/common/register'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    hidden: true,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/common/dashboard')
    }]
  }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({y: 0}),
  routes: constantRouterMap
})

// 根据权限动态加载路由表
export const asyncRouterMap = [

  {
    path: '/table',
    component: Layout,
    redirect: '/table/anime',
    name: 'Table',
    meta: {title: '表', icon: 'table'},
    children: [
      {
        path: 'anime',
        name: 'Anime',
        component: () => import('@/views/table/anime'),
        meta: {
          title: '动画',
          icon: 'example',
          roles:['ROLE_ADMIN']
        }
      },
      {
        path: 'company',
        name: 'Company',
        component: () => import('@/views/table/company'),
        meta: {
          title: '动画公司',
          icon: 'example',
          roles:['ROLE_USER']
        }
      },
      {
        path: 'director',
        name: 'Director',
        component: () => import('@/views/table/director'),
        meta: {
          title: '动画导演',
          icon: 'example'
        }
      },
    ]
  },

  {
    path: '/chart',
    component: Layout,
    redirect: '/chart/bar',
    name: 'Chart',
    meta: {
      title: '图',
      icon: 'chart',
      roles: ['ROLE_ADMIN']
    },
    children: [
      {
        path: 'bar',
        component: () => import('@/views/chart/barChart'),
        name: 'keyboardChart',
        meta: {title: 'bar', icon: "example"}
      },
      {
        path: 'line',
        component: () => import('@/views/chart/lineChart'),
        name: 'lineChart',
        meta: {title: 'line', icon: "example"}
      },
      {
        path: 'pie',
        component: () => import('@/views/chart/pieChart'),
        name: 'pieChart',
        meta: {title: 'pie', icon: "example"}
      },
      {
        path: 'mix',
        component: () => import('@/views/chart/mixChart'),
        name: 'mixChart',
        meta: {title: 'mix', icon: "example"}
      }
    ]
  },

  {path: '*', redirect: '/404', hidden: true}
];

